package com.yitao.client.constant;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Function:
 * Date: 2018/12/25
 *
 * @author skipper
 * @desc
 * @see
 */
public abstract class OrderStatusEmnu {


    /**
     * 前端订单列表分类的订单状态
     */
    public enum APP_SHOW_ORDER_STATUS_IN_LIST {
        WAIT_APPROVAL(1, "待付款"),
        PENDING_GROUP(2, "待拼团"),
        APPROVAL(3, "待发货"),
        NOT_PASS(4, "待收货"),
        TO_REVIEW(5, "待评价"),
        REFUND(6, "退款/售后");

        private Integer code;
        private String msg;
        //        private static final Map<String, String> map = new HashMap<>();
        private static final List<Map<String, String>> list = new ArrayList<>();

        static {
            for (APP_SHOW_ORDER_STATUS_IN_LIST app : APP_SHOW_ORDER_STATUS_IN_LIST.values()) {
                Map<String, String> map = new HashMap<>();
                map.put("code", app.code.toString());
                map.put("msg", app.msg);
                list.add(map);
            }
        }

        APP_SHOW_ORDER_STATUS_IN_LIST(Integer code, String msg) {
            this.code = code;
            this.msg = msg;
        }

        public Integer getCode() {
            return code;
        }

        public String getMsg() {
            return msg;
        }

        /**
         * 订单状态枚举
         *
         * @return
         */
        public static List<Map<String, String>> getOrderStatusEnum() {
            return list;
        }
    }

    /**
     * 订单状态
     */
    public enum ORDER_STATUS {
        WAIT_APPROVAL(10, "未审核"),
        APPROVAL(20, "审核通过"),
        NOT_PASS(21, "审核不通过"),
        WAIT_GROUP(25, "待拼团"),
        TO_REVIEW(30, "待复核"),
        FINISH(60, "交易完成"),
        OVER(70, "订单完结"),
        CANCEL(-1, "撤销"),
        SELLER_CANCEL(-2,"卖家取消"),
        ORDER_ERROR(0, "订单异常");

        private Integer code;
        private String msg;

        ORDER_STATUS(Integer code, String msg) {
            this.code = code;
            this.msg = msg;
        }

        public Integer getCode() {
            return code;
        }

        public String getMsg() {
            return msg;
        }
    }

    /**
     * 支付状态
     */
    public enum PAY_STATUS {
        // TODO 上线前将退款的状态替换成下面那个枚举
        NOT_PAY(10, "未支付"),
        HAVE_PAY(20, "已支付"),

        APPLYING_FOR_REFUND(-10, "申请退款中"),
        NOT_REFUND(-20, "退款中"),
        REFUND(-30, "已退款"),
        REFUND_ERROR(-40, "退款失败"),
        ;

        private Integer code;
        private String msg;

        PAY_STATUS(Integer code, String msg) {
            this.code = code;
            this.msg = msg;
        }

        public Integer getCode() {
            return code;
        }

        public String getMsg() {
            return msg;
        }

        /**
         * 根据code返回message
         * @param code
         * @return
         */
        public String getPayStatusMsg(Integer code){
            for (PAY_STATUS payStatus:OrderStatusEmnu.PAY_STATUS.values()){
                if (payStatus.code.equals(code)){
                    return payStatus.msg;
                }
            }
            return null;

        }
    }

    /**
     * 退款状态
     */
    public enum REFUND_STATUS{
        STANDARD_ORDER(0, "正常订单"),
        APPLYING_FOR_REFUND(-10, "申请退款中"),
        PORTION_APPLYING_FOR_REFUND(-11, "部分申请退款中"),
        REFUND_REJECTED(-15, "退款申请驳回"),
        NOT_REFUND(-20, "退款中"),
        PORTION_REFUND_OF(-25, "部分退款中"),
        REFUND(-30, "已退款"),
        PORTION_REFUND(-35, "部分已退款"),
        REFUND_ERROR(-40, "退款失败")
        ;

        private Integer code;
        private String msg;
        private static final Map<String, String> map = new HashMap<>();
        private static final List<Map<String, Object>> list = new ArrayList<>();

        static {
            for(OrderStatusEmnu.REFUND_STATUS refund_status: OrderStatusEmnu.REFUND_STATUS.values()){
                map.put(refund_status.getCode().toString(), refund_status.msg);
                Map<String, Object> temp = new HashMap<>();
                temp.put("code", refund_status.getCode());
                temp.put("msg", refund_status.getMsg());
                list.add(temp);
            }
        }

        REFUND_STATUS(Integer code, String msg) {
            this.code = code;
            this.msg = msg;
        }

        public Integer getCode() {
            return code;
        }

        public String getMsg() {
            return msg;
        }

        public static String getMsg(String code){
            return map.get(code);
        }

        public static List<Map<String, Object>> getRefundEnum(){
            return list;
        }
    }

    /**
     * 物流状态
     */
    public enum LOGISTIC_STATUS {
        IN_THE_STOCK(10, "备货中"),
        WAIT_SHIP(20, "待发货"),
        SHIPPED(30, "已发货"),
        HAVE_BEEN_SIGNED(40, "已签收"),
        PORTION_SHIPPED(50, "部分发货")
        ;

        private Integer code;
        private String msg;
        private static final Map<Integer, String> map = new HashMap<>();

        static {
            for(OrderStatusEmnu.LOGISTIC_STATUS logistic_status: OrderStatusEmnu.LOGISTIC_STATUS.values()) {
                map.put(logistic_status.code, logistic_status.getMsg());
            }
        }

        LOGISTIC_STATUS(Integer code, String msg) {
            this.code = code;
            this.msg = msg;
        }

        public Integer getCode() {
            return code;
        }

        public String getMsg() {
            return msg;
        }

        public static String getMsgByCode(Integer code){
            return map.get(code);
        }
    }

    /**
     * 是否缺货标记
     */
    public enum OUT_STOCK{
        NO(0), // 否
        YES(1); // 是

        private Integer code;

        OUT_STOCK(Integer code) {
            this.code = code;
        }

        public Integer getCode() {
            return code;
        }
    }

    /**
     * 订单显示状态
     */
    public enum ORDER_SHOW_STATUS {

        PENDING(10, "待付款"),
        PARTIAL_PAYMENT(11, "部分付款"),
        WAIT_APPROVAL(20, "待审核"),
        WAIT_GROUP(25, "待拼团"),
        WAIT_DELIVER(30, "待发货"),
        ALREADY_PAID(31, "已拣货"),
        PARTIAL_DELIVER(32, "部分发货"),
        SHIPPED(40, "已发货"),
        TRADE_FINISHED(60, "订单待评价"),
        OVER(70, "订单完结"),
        CANCELED(-20, "已取消"),
        SELLER_CANCEL(-21,"卖家取消"),
        APPLY_CANCEL(-10, "退款申请中"),

        /************** 新增的退款状态枚举 *****************/
        APPLYING_FOR_REFUND(-10, "申请退款中"),
        PORTION_APPLYING_FOR_REFUND(-11, "部分申请退款中"),
        NOT_REFUND(-20, "退款中"),
        PORTION_REFUND_OF(-25, "部分退款中"),
        REFUND(-30, "已退款"),
        PORTION_REFUND(-35, "部分退款"),
        REFUND_ERROR(-40, "退款失败"),

        REFUND_REJECTED(-15, "退款申请驳回"),

        /*****************  以下三个暂停使用 *********************/
        REFUND_CANCEL_ING(-25, "退款中"),
        REFUND_CANCEL(-30, "已退款"),
        REFUND_FINISHED(-40, "退款失败"),

        ERROR_ORDER(00, "订单异常"),;

        private Integer key;
        private String value;
        public static Map<Integer, String> map = new HashMap<>();

        static {
            for(OrderStatusEmnu.ORDER_SHOW_STATUS order_show_status: OrderStatusEmnu.ORDER_SHOW_STATUS.values()){
                map.put(order_show_status.getKey(), order_show_status.getValue());
            }
        }

        ORDER_SHOW_STATUS(Integer key, String value) {
            this.key = key;
            this.value = value;
        }

        public Integer getKey() {
            return key;
        }

        public void setKey(Integer key) {
            this.key = key;
        }

        public String getValue() {
            return value;
        }

        public void setValue(String value) {
            this.value = value;
        }

        public static String getValueByKey(Integer key){
            return map.get(key);
        }
    }

    /**
     * 订单显示状态
     */
    public enum WECHAT_SEND_ORDER_STATUS {

        WAIT_GROUP(25, "待拼团"),
        WAIT_DELIVER(30, "待发货"),
        GROUP_SUCCESS(31, "拼团成功"),
        SHIPPED(40, "已发货"),
        TRADE_FINISHED(60, "已签收"),
        OVER(70, "订单完结[订单已评价]"),
        ;

        private Integer key;

        private String value;

        WECHAT_SEND_ORDER_STATUS(Integer key, String value) {
            this.key = key;
            this.value = value;
        }

        public Integer getKey() {
            return key;
        }

        public void setKey(Integer key) {
            this.key = key;
        }

        public String getValue() {
            return value;
        }
        public void setValue(String value) {
            this.value = value;
        }
    }

    /**
     * 运营后台 订单显示枚举
     */

    public enum CmsOrderShowStatusEnum {

        ALL(0, "全部"),
        PENDING(ORDER_SHOW_STATUS.PENDING.key, ORDER_SHOW_STATUS.PENDING.value),
        WAIT_GROUP(ORDER_SHOW_STATUS.WAIT_GROUP.key, ORDER_SHOW_STATUS.WAIT_GROUP.value),
        WAIT_DELIVER(ORDER_SHOW_STATUS.WAIT_DELIVER.key, ORDER_SHOW_STATUS.WAIT_DELIVER.value),
        SHIPPED(ORDER_SHOW_STATUS.SHIPPED.key, ORDER_SHOW_STATUS.SHIPPED.value),
        TRADE_FINISHED(ORDER_SHOW_STATUS.TRADE_FINISHED.key, ORDER_SHOW_STATUS.TRADE_FINISHED.value),
        CANCELED(ORDER_SHOW_STATUS.CANCELED.key, ORDER_SHOW_STATUS.CANCELED.value);

        private static final Map<Integer, CmsOrderShowStatusEnum> map = new HashMap<>();

        static {
            CmsOrderShowStatusEnum[] values = CmsOrderShowStatusEnum.values();
            for (CmsOrderShowStatusEnum item : values) {
                map.put(item.code, item);
            }
        }

        private final Integer code;
        private final String name;

        private CmsOrderShowStatusEnum(Integer code, String name) {
            this.code = code;
            this.name = name;
        }

        public static CmsOrderShowStatusEnum getEnum(Integer code) {
            return map.get(code);
        }

        public Integer getCode() {
            return code;
        }

        public String getName() {
            return name;
        }
    }

    /**
     * 快递100物流信息状态值------国内快递使用
     */
    public enum LOGISTICS_INFORMATION {
        ON_THE_WAY(0, "运输中"),
        COLLECTED(1, "已揽件"),
        DIFFICULT(2, "疑难"),
        ALREADY_SIGNED(3, "已签收"),
        WITHDRAWAL(4, "退签"),
        IN_THE_DELIVERY(5, "派送中"),
        BACK_TO_THE(6, "退回"),
        TRANSFER_ORDER(7, "转单"),
        HAS_BEEN_SHIPPED(8, "已发货"),
        CONFIRM_THE_GOODS(9, "已确认收货"),

        HAS_BEEN_SHIPPED_MESSAGE(10, "包裹正在等待揽件"),
        TRANSFER_ORDER_MESSAGE(11, "退回/转单中");

        private final Integer code;
        private final String msg;

        LOGISTICS_INFORMATION(Integer code, String msg) {
            this.code = code;
            this.msg = msg;
        }

        public Integer getCode() {
            return code;
        }

        public String getMsg() {
            return msg;
        }
    }

    /**
     * 描述: 快递信息状态时，国际物流(旧版，废除)
     *
     * @param
     * @return
     * @auther: Kien
     */
    public enum EXPRESSAGE_STATUS {
        HAS_BEEN_SHIPPED_MESSAGE(10, "采购中"),
        WAIT_SHIP(10, "待发货"),
        HAS_BEEN_SHIPPED(11, "已发货"),
        COLLECTED(0, "采购运输中"),
        IN_TRANSIT(1, "转运中"),
        IN_INTERNATIONAL_TRANSPOR(2, "国际运输中"),
        CUSTOMS_CLEARANCE(3, "清关中"),
        IN_DOMESTIC_TRANSPORT(4, "国内运输中"),
        FAILURE_TO_SIGN(5, "签收失败"),
        HAVE_BEEN_SIGNED(6, "已签收"),
        CANCEL(7, "取消");

        private final Integer code;
        private final String msg;

        EXPRESSAGE_STATUS(Integer code, String msg) {
            this.code = code;
            this.msg = msg;
        }

        public Integer getCode() {
            return code;
        }

        public String getMsg() {
            return msg;
        }
    }
    
    /**
     *
     * 功能描述: 新版自定义快递信息状态
     * 当前code不能修改，否则无法从当前状态值获取到他的下一个状态值
     *
     * @param
     * @return 
     * @auther: Kien
     * @date: 2019/5/16 20:35
     */
    public enum NEW_EXPRESSAGE_STATUS{
        HAS_BEEN_SHIPPED_MESSAGE(0, "买手采购中"),
        WAIT_SHIP(-1, "待发货"),
        HAS_BEEN_SHIPPED(11, "已发货"),
        OVERSEAS_IN_TRANSIT(100, "境外运输中"),
        WAREHOUSE_IN_THE_OPERATION(200, "仓库操作中"),
        CROSS_BORDER_IN_TRANSIT(300, "跨境运输中"),
        CUSTOMS_CLEARANCE(400, "清关中"),
        DOMESTIC_IN_TRANSIT(500, "国内运输中"),
        IN_THE_DELIVERY(600, "派送中"),
        WAITING_SIGN_FOR(700, "待签收"),
        WAITING_TAKE(800, "待取件"), // 2019.08.22修改，让待取件状态在已签收前面
        HAVE_BEEN_SIGNED(900, "已签收"),
        FAILURE_TO_SIGN(1000, "签收失败"),
        ;

        private final Integer code;
        private final String msg;
        private static Map<Integer, String> map = new HashMap<>();
        private static Map<String, Integer> codeMap = new HashMap<>();
        private static List<Map<String, Object>> list = new ArrayList<>();

        static {
            for(OrderStatusEmnu.NEW_EXPRESSAGE_STATUS new_expressage_status: OrderStatusEmnu.NEW_EXPRESSAGE_STATUS.values()){
                map.put(new_expressage_status.getCode(), new_expressage_status.getMsg());
                codeMap.put(new_expressage_status.getMsg(), new_expressage_status.getCode());
                if(new_expressage_status.getCode() >= 100 && new_expressage_status.getCode() < 1000) { // 只保存1-9节点状态
                    Map<String, Object> temp = new HashMap<>();
                    temp.put("key", new_expressage_status.getCode());
                    temp.put("value", new_expressage_status.getMsg());
                    list.add(temp);
                }
            }
        }

        NEW_EXPRESSAGE_STATUS(Integer code, String msg) {
            this.code = code;
            this.msg = msg;
        }

        public Integer getCode() {
            return code;
        }

        public String getMsg() {
            return msg;
        }

        /**
         *
         * 功能描述: 根据code获取msg
         *
         * @param code
         * @return
         * @auther: Kien
         * @date: 2019/6/12 15:34
         */
        public static String getMsgByCode(Integer code){
            return map.get(code);
        }

        /**
         *
         * 功能描述: 根据msg获取code
         *
         * @param msg
         * @return
         * @auther: Kien
         * @date: 2019/6/12 15:35
         */
        public static Integer getCodeByMsg(String msg){
            return codeMap.get(msg);
        }

        /**
         *
         * 功能描述: 获取物流节点状态和状态码
         *
         * @return list
         * @auther: Kien
         * @date: 2019/6/17 21:14
         */
        public static List<Map<String, Object>> getList(){
            return list;
        }

    }

    /**
     * 描述: 退款状态枚举
     *
     * @param
     * @return
     * @auther: Kien
     */
    public enum ORDER_REFUND_ENUM {
        APPLYING_FOR_REFUND(-10, "申请退款中"),
        REFUND_REJECT(-15, "退款申请驳回"),
        NOT_REFUND(-20, "退款中"),
        REFUND(-30, "已退款"),
        REFUND_ERROR(-40, "退款失败"),;

        private static final Map<Integer, ORDER_REFUND_ENUM> map = new HashMap<>();

        static {
            ORDER_REFUND_ENUM[] values = ORDER_REFUND_ENUM.values();
            for (ORDER_REFUND_ENUM responseDtoEnum : values) {
                map.put(responseDtoEnum.key, responseDtoEnum);
            }
        }

        private Integer key;

        private String value;

        ORDER_REFUND_ENUM(Integer key, String value) {
            this.key = key;
            this.value = value;
        }

        public Integer getKey() {
            return key;
        }

        public void setKey(Integer key) {
            this.key = key;
        }

        public String getValue() {
            return value;
        }

        public void setValue(String value) {
            this.value = value;
        }

        public static ORDER_REFUND_ENUM getEnum(Integer value) {
            return map.get(value);
        }
    }

    /**
     * 描述: 退款类型枚举
     *
     * @param
     * @return
     * @auther: Kien
     */
    public enum REFUND_TYPE {
        ORDINARY_REFUND(1, "整单退款"),
        STOCK_OUT_REFUND(2, "缺货退款"),
//        COMPENSATION_REFUND(3, "赔偿退款(部分退款)"),
        ;

        private Integer key;
        private String value;
        private static List<Map<String, String>> list = new ArrayList<>();

        static {
            for (OrderStatusEmnu.REFUND_TYPE refund_type : OrderStatusEmnu.REFUND_TYPE.values()) {
                Map<String, String> map = new HashMap<>();
                map.put("key", refund_type.getKey().toString());
                map.put("value", refund_type.getValue());
                list.add(map);
            }
        }

        REFUND_TYPE(Integer key, String value) {
            this.key = key;
            this.value = value;
        }

        public Integer getKey() {
            return key;
        }

        public void setKey(Integer key) {
            this.key = key;
        }

        public String getValue() {
            return value;
        }

        public void setValue(String value) {
            this.value = value;
        }

        /**
         * 获取退款类型枚举
         *
         * @return
         */
        public static List<Map<String, String>> getRefundType() {
            return list;
        }


        private static final Map<Integer, REFUND_TYPE> map = new HashMap<>();

        static {
            REFUND_TYPE[] values = REFUND_TYPE.values();
            for (REFUND_TYPE responseDtoEnum : values) {
                map.put(responseDtoEnum.key, responseDtoEnum);
            }
        }

        public static REFUND_TYPE getEnum(Integer value) {
            return map.get(value);
        }


    }

    /**
     * 退款原因列表
     */
    public enum REFUND_REASON {
        BOUGHT_THE_WRONG(1, "不想要了/拍错了"),
        EXPRESSAGE_REASON(2, "快递原因"),
        NOT_YET_SHIPPED(3, "卖家实际未发货"),
        CONSENSUS_REFUND(4, "协商一致退款"),
        OUT_OF_STOCK(5, "缺货"),
        OTHER(6, "其他"),
        ;

        private Integer key;
        private String value;
        private static List<Map<String, String>> list = new ArrayList<>();

        static {
            for (OrderStatusEmnu.REFUND_REASON refund_reason : OrderStatusEmnu.REFUND_REASON.values()) {
                Map<String, String> map = new HashMap<>();
                map.put("key", refund_reason.getKey().toString());
                map.put("value", refund_reason.getValue());
                list.add(map);
            }
        }

        REFUND_REASON(Integer key, String value) {
            this.key = key;
            this.value = value;
        }

        public Integer getKey() {
            return key;
        }

        public void setKey(Integer key) {
            this.key = key;
        }

        public String getValue() {
            return value;
        }

        public void setValue(String value) {
            this.value = value;
        }

        public static List<Map<String, String>> getRefundReason() {
            return list;
        }

        private static final Map<Integer, REFUND_REASON> map = new HashMap<>();

        static {
            REFUND_REASON[] values = REFUND_REASON.values();
            for (REFUND_REASON responseDtoEnum : values) {
                map.put(responseDtoEnum.key, responseDtoEnum);
            }
        }
        public static REFUND_REASON getEnum(Integer value) {
            return map.get(value);
        }
    }

    /**
     * 订单商品缺货状态
     */
    public enum PROCUREMENT_STATUS{
        IN_THE_PROCUREMENT(1, "采购中"),
        PROCUREMENT_TO_COMPLETE(2, "采购完成"),
        OUT_OF_STOCK_PURCHASE_COMPLETED(3, "缺买完成"),
        OUT_OF_STOCK(4, "缺货")
        ;

        private final Integer code;
        private final String msg;

        PROCUREMENT_STATUS(Integer code, String msg){
            this.code = code;
            this.msg = msg;
        }

        public Integer getCode() {
            return code;
        }

        public String getMsg() {
            return msg;
        }
    }

}
